package org.jebert.javamessage.model;

import java.net.InetAddress;
import org.jebert.javamessage.control.Translator;
import org.jebert.javamessage.view.ChatWindow;

public class Contact {

    private InetAddress host;
    private int port;
    private long idleTime;
    private String contactName;
    private String cn;
    private boolean exist = false;
    private Translator translator;


    public Contact(InetAddress host, int port, long idleTime, String contactName, Translator translator) {
        this.host = host;
        this.port = port;
        this.idleTime = idleTime;
        this.contactName = contactName;
        this.translator = translator;
        this.cn = translator.translateIt("Contact Name: ");
    }



    public void updateContact() {
        this.setIdleTime(System.currentTimeMillis());
    }

    public InetAddress getHost() {
        return host;
    }

    public void setHost(InetAddress host) {
        this.host = host;
    }

    public long getIdleTime() {
        return idleTime;
    }

    public void setIdleTime(long idleTime) {
        this.idleTime = idleTime;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    public void setExist(boolean exist) {
        this.exist = exist;
    }

    public boolean getExist() {
        return this.exist;
    }

    public Translator getTranslator() {
        return translator;
    }

    public void setTranslator(Translator translator) {
        this.translator = translator;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Contact other = (Contact) obj;
        if (this.host != other.host && (this.host == null || !this.host.equals(other.host))) {
            return false;
        }
        if (this.port != other.port) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 77 * hash + (this.host != null ? this.host.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return cn + " " + contactName;
    }
}
